<template>
	<view style="margin-top: 170rpx;background-color: #ffffff;">
		<u-navbar :title="index==='0'?'我的关注':'我的粉丝'" @rightClick="rightClick" :autoBack="true">
		</u-navbar>

		<u-list @scrolltolower="scrolltolower">
			<u-list-item v-for="(item, index) in indexList" :key="index">
				<u-cell :title="item.userName" @click="turnto(item.id)">
					<u-avatar slot="icon" shape="square" size="35" :src="item.userPic"
						customStyle="margin: -3px 5px -3px 0"></u-avatar>
				</u-cell>
			</u-list-item>
		</u-list>

	</view>
</template>

<script>
	export default {
		data() {
			return {
				timer: null,
				timer2: null,
				total: 0,
				index: '',
				indexList: [],
				pageSize: 6,
				pageNum: 1,
			}
		},
		onUnload() {
			console.log(123)
			if (this.timer2) {
				clearTimeout(this.timer2); // 清除定时器  
			}
		},
		onPullDownRefresh() {
			uni.showLoading({
				title: '加载中'
			});
			this.params.pageNum = 1
			this.getList()
			this.timer = setTimeout(() => {
				uni.stopPullDownRefresh()
				uni.hideLoading();
			}, 1000)
		},
		onReachBottom() {
			this.getBottom()
		},
		methods: {
			turnto(id){
				uni.navigateTo({
					url:"/pagesa/persionalPage/persionalPage?id="+id
				})
			},
			async getBottom() {
				const that = this
				if (this.loveList.length < this.total) {
					this.pageNum++
					uni.showLoading({
						title: '加载中'
					});
					uni.request({
						url: that.$baseurl + "/font/getGuanOrFen",
						method: 'GET',
						data: that.params,
						success(res) {
							that.loveList = [...that.loveList, ...res.data.rows]
						}
					})
					uni.hideLoading();
				} else {
					this.$refs.uToast.show({
						type: 'default',
						title: '默认主题',
						message: "到底了...",
						iconUrl: 'https://cdn.uviewui.com/uview/demo/toast/default.png'
					})
				}
			},
			async getList() {
				if (!this.$isLogin()) {
					return;
				}
				var user = uni.getStorageSync("loginUser")
				const res = await this.$myRuquest({
					url: '/font/getGuanOrFen?index=' + this.index + '&userId=' + user.id + '&pageSize=' + this
						.pageSize + '&pageNum=' + this.pageNum,
				})
				this.indexList = res.data.rows
				this.total = res.data.rows
			},
			rightClick() {
				uni.navigateBack()
				console.log('rightClick');
			},
			leftClick() {
				uni.navigateBack()
				console.log('leftClick');
			},
		},
		onLoad(options) {
			console.log(options.index)
			var index = options.index
			if (index !== null && index !== '' && index !== undefined) {
				this.index = index
			}
			this.getList()
		},
	}
</script>

<style>

</style>